from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-10-03 14:12:08.163912
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 03, Oct, 2021
Time: 14:12:13
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.4954
Nobs: 433.000 HQIC: -47.0075
Log likelihood: 4809.83 FPE: 2.75343e-21
AIC: -47.3415 Det(Omega_mle): 2.24198e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.429729 0.091202 4.712 0.000
L1.Burgenland 0.104620 0.047161 2.218 0.027
L1.Kärnten -0.113186 0.023718 -4.772 0.000
L1.Niederösterreich 0.148540 0.101011 1.471 0.141
L1.Oberösterreich 0.115559 0.099460 1.162 0.245
L1.Salzburg 0.286445 0.049770 5.755 0.000
L1.Steiermark 0.035859 0.066035 0.543 0.587
L1.Tirol 0.105605 0.052273 2.020 0.043
L1.Vorarlberg -0.101456 0.046868 -2.165 0.030
L1.Wien -0.005154 0.090676 -0.057 0.955
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.013960 0.207969 0.067 0.946
L1.Burgenland -0.049332 0.107542 -0.459 0.646
L1.Kärnten 0.037670 0.054084 0.697 0.486
L1.Niederösterreich -0.211891 0.230336 -0.920 0.358
L1.Oberösterreich 0.493792 0.226800 2.177 0.029
L1.Salzburg 0.305285 0.113490 2.690 0.007
L1.Steiermark 0.106045 0.150580 0.704 0.481
L1.Tirol 0.311463 0.119198 2.613 0.009
L1.Vorarlberg 0.000091 0.106874 0.001 0.999
L1.Wien 0.004881 0.206769 0.024 0.981
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.243649 0.046196 5.274 0.000
L1.Burgenland 0.088970 0.023888 3.724 0.000
L1.Kärnten -0.003561 0.012014 -0.296 0.767
L1.Niederösterreich 0.207848 0.051164 4.062 0.000
L1.Oberösterreich 0.155875 0.050379 3.094 0.002
L1.Salzburg 0.038618 0.025209 1.532 0.126
L1.Steiermark 0.025069 0.033448 0.749 0.454
L1.Tirol 0.067379 0.026477 2.545 0.011
L1.Vorarlberg 0.061053 0.023740 2.572 0.010
L1.Wien 0.116457 0.045929 2.536 0.011
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.186501 0.045006 4.144 0.000
L1.Burgenland 0.045967 0.023273 1.975 0.048
L1.Kärnten -0.006346 0.011704 -0.542 0.588
L1.Niederösterreich 0.141891 0.049846 2.847 0.004
L1.Oberösterreich 0.318481 0.049081 6.489 0.000
L1.Salzburg 0.100222 0.024560 4.081 0.000
L1.Steiermark 0.128727 0.032587 3.950 0.000
L1.Tirol 0.076908 0.025795 2.981 0.003
L1.Vorarlberg 0.056333 0.023128 2.436 0.015
L1.Wien -0.048709 0.044746 -1.089 0.276
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.207973 0.089365 2.327 0.020
L1.Burgenland -0.049537 0.046211 -1.072 0.284
L1.Kärnten -0.032910 0.023240 -1.416 0.157
L1.Niederösterreich 0.114220 0.098976 1.154 0.248
L1.Oberösterreich 0.173634 0.097457 1.782 0.075
L1.Salzburg 0.251148 0.048767 5.150 0.000
L1.Steiermark 0.076416 0.064705 1.181 0.238
L1.Tirol 0.122234 0.051220 2.386 0.017
L1.Vorarlberg 0.115598 0.045924 2.517 0.012
L1.Wien 0.025250 0.088849 0.284 0.776
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.037884 0.069143 0.548 0.584
L1.Burgenland 0.022980 0.035754 0.643 0.520
L1.Kärnten 0.054636 0.017981 3.039 0.002
L1.Niederösterreich 0.201891 0.076580 2.636 0.008
L1.Oberösterreich 0.336154 0.075404 4.458 0.000
L1.Salzburg 0.047791 0.037732 1.267 0.205
L1.Steiermark -0.004478 0.050063 -0.089 0.929
L1.Tirol 0.111836 0.039630 2.822 0.005
L1.Vorarlberg 0.068747 0.035532 1.935 0.053
L1.Wien 0.124044 0.068744 1.804 0.071
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.197597 0.084488 2.339 0.019
L1.Burgenland 0.013534 0.043689 0.310 0.757
L1.Kärnten -0.057578 0.021972 -2.621 0.009
L1.Niederösterreich -0.127064 0.093574 -1.358 0.174
L1.Oberösterreich 0.195797 0.092138 2.125 0.034
L1.Salzburg 0.035557 0.046106 0.771 0.441
L1.Steiermark 0.286609 0.061174 4.685 0.000
L1.Tirol 0.490341 0.048424 10.126 0.000
L1.Vorarlberg 0.077099 0.043418 1.776 0.076
L1.Wien -0.109239 0.084000 -1.300 0.193
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.156656 0.092281 1.698 0.090
L1.Burgenland -0.012618 0.047719 -0.264 0.791
L1.Kärnten 0.063572 0.023998 2.649 0.008
L1.Niederösterreich 0.196010 0.102206 1.918 0.055
L1.Oberösterreich -0.123652 0.100637 -1.229 0.219
L1.Salzburg 0.233210 0.050358 4.631 0.000
L1.Steiermark 0.149425 0.066816 2.236 0.025
L1.Tirol 0.047693 0.052891 0.902 0.367
L1.Vorarlberg 0.130463 0.047423 2.751 0.006
L1.Wien 0.161184 0.091749 1.757 0.079
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.480716 0.050138 9.588 0.000
L1.Burgenland -0.007753 0.025927 -0.299 0.765
L1.Kärnten -0.009589 0.013039 -0.735 0.462
L1.Niederösterreich 0.203707 0.055530 3.668 0.000
L1.Oberösterreich 0.252968 0.054678 4.627 0.000
L1.Salzburg 0.024174 0.027361 0.884 0.377
L1.Steiermark -0.021078 0.036302 -0.581 0.561
L1.Tirol 0.066194 0.028737 2.303 0.021
L1.Vorarlberg 0.060835 0.025766 2.361 0.018
L1.Wien -0.047745 0.049849 -0.958 0.338
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.019921 0.080790 0.138678 0.131625 0.046916 0.074565 -0.002766 0.188255
Kärnten 0.019921 1.000000 -0.043105 0.130094 0.048578 0.071440 0.452084 -0.089766 0.088832
Niederösterreich 0.080790 -0.043105 1.000000 0.282951 0.082675 0.266950 0.031137 0.136187 0.261816
Oberösterreich 0.138678 0.130094 0.282951 1.000000 0.176718 0.288001 0.157930 0.100765 0.135134
Salzburg 0.131625 0.048578 0.082675 0.176718 1.000000 0.125769 0.057234 0.106714 0.049694
Steiermark 0.046916 0.071440 0.266950 0.288001 0.125769 1.000000 0.131752 0.090118 -0.014013
Tirol 0.074565 0.452084 0.031137 0.157930 0.057234 0.131752 1.000000 0.049594 0.120043
Vorarlberg -0.002766 -0.089766 0.136187 0.100765 0.106714 0.090118 0.049594 1.000000 -0.047359
Wien 0.188255 0.088832 0.261816 0.135134 0.049694 -0.014013 0.120043 -0.047359 1.000000